package org.java8newfeature.stream;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static java.util.stream.Collectors.reducing;

public class Section11 {
    public static void main(String[] args) {
        Stream.of("Monkey", "Lion", "Giraffe", "Lemur", "Lion")
                .parallel()
                .forEach(System.out::println);

        Stream.of("Monkey", "Lion", "Giraffe", "Lemur", "Lion")
                .parallel()
                .forEachOrdered(System.out::println);

        Set<String> collect = Stream.of("Monkey", "Lion", "Giraffe", "Lemur", "Lion")
                .collect(Collectors.toSet());

        LinkedList<String> collect1 = Stream.of("Monkey", "Lion", "Giraffe", "Lemur", "Lion")
                .collect(Collectors.toCollection(LinkedList::new));

        String[] strings = Stream.of("Monkey", "Lion", "Giraffe", "Lemur", "Lion")
                .toArray(String[]::new);
   /*     Map<String, Integer> collect2 = Stream.of("Monkey", "Lion", "Giraffe", "Lemur", "Lion","aaaa")
                .distinct()
                .collect(Collectors.toMap(
                       Function.identity(),
                        s -> (int) s.chars().count()
                ));

        collect2.forEach((k,v)-> System.out.println(k+v));*/

       /*  Stream.of("Monkey", "Lion", "Giraffe", "Lemur", "Lion")
                .collect(Collectors.groupingBy(e->e.charAt(0), counting()))
                 .forEach((c,ss)-> System.out.printf("c:%s   ss=%s\n",c,ss));*/

        boolean containTwo = IntStream.of(1, 2, 3, 4).anyMatch(i -> i == 2);

        long count = Stream.of("Monkey", "Lion", "Giraffe", "Lemur").count();

        int sum = IntStream.of(1, 2, 3).sum();

        OptionalDouble average = IntStream.of(1, 2, 3,4).average();

        System.out.println(average.orElse(0));

        System.out.println(IntStream.of(1, 2, 3).max().orElse(10));

        System.out.println(IntStream.of(1, 2, 3).summaryStatistics());
    }

}
